<extend name="Public/base"/>

<block name="body">
    <div class="main-title">
        <h2>新增商品</h2>
    </div>
    <form action="{:U()}" method="post" class="form-horizontal" enctype="multipart/form-data">
        <div class="form-item">
            <label class="item-label">商品名称<span class="check-tips"></span></label>
            <div class="controls">
                <select name="gid">
                        <option value="">请选择</option>
                    <foreach name="res1" item="v">
                        <option value="{$v['id']}">{$v.title}</option>
                    </foreach>
                </select>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">颜色<span class="check-tips"></span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="color">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">属性</label>
            <div class="controls">
                <input type="text" class="text input-large" name="size">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">上传图片</label>
            <div style="height:180px;" id="dd">
            </div>
            <hr>
            <div style="clear:both"></div>
            <div id="upload-img">
                <input type="file" name="pic[]" id="doc" multiple  onchange="javascript:setImagePreviews();">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">价格</label>
            <div class="controls">
                <input type="text" class="text input-large" name="cost">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">剩余数量</label>
            <div class="controls">
                <input type="text" class="text input-large" name="count">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">状态</label>
            <div class="controls">
                <label class="radio">
                    <input type="radio" name="status" value="1">显示
                    <input type="radio" name="status" value="0">不显示
                </label>
            </div>
        </div>
        <br>
        <div class="form-item">
            <button class="btn submit-btn" type="submit">确 定</button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
    </form>
</block>

<block name="script">
    <script type="text/javascript">
        //导航高亮
        highlight_subnav('{:U('Property/index')}');

           //下面用于多图片上传预览功能
    function setImagePreviews(avalue) {
        //获取选择图片的对象
        var docObj = document.getElementById("doc");
        //后期显示图片区域的对象
        var dd = document.getElementById("dd");
        dd.innerHTML = "";
        //得到所有的图片文件
        var fileList = docObj.files;
        //循环遍历
        for (var i = 0; i < fileList.length; i++) {    
            //动态添加html元素        
            dd.innerHTML += "<div style='float:left' > <img id='img" + i + "'  /> </div>";
            //获取图片imgi的对象
            var imgObjPreview = document.getElementById("img"+i); 
            
            if (docObj.files && docObj.files[i]) {
                //火狐下，直接设img属性
                imgObjPreview.style.display = 'block';
                imgObjPreview.style.width = '200px';
                imgObjPreview.style.height = '180px';
                //imgObjPreview.src = docObj.files[0].getAsDataURL();
                //火狐7以上版本不能用上面的getAsDataURL()方式获取，需要以下方式
                imgObjPreview.src = window.URL.createObjectURL(docObj.files[i]);   //获取上传图片文件的物理路径
            }
            else {
                //IE下，使用滤镜
                docObj.select();
                var imgSrc = document.selection.createRange().text;
                //alert(imgSrc)
                var localImagId = document.getElementById("img" + i);
               //必须设置初始大小
                localImagId.style.width = "200px";
                localImagId.style.height = "180px";
                //图片异常的捕捉，防止用户修改后缀来伪造图片
                try {
                    localImagId.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
                    localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
                }
                catch (e) {
                    alert("您上传的图片格式不正确，请重新选择!");
                    return false;
                }
                imgObjPreview.style.display = 'none';
                document.selection.empty();
            }
        }  
        return true;
    }
    </script>
</block>
